/*
 * @Author       : 方木
 * @LastEditors  : 方木
 * @email        : ethan_zzz@yeah.net
 * @github       : https://github.com/ethan-Zzz
 * @Date         : 2020-06-18 18:07:27
 * @LastEditTime : 2021-01-08 16:01:58
 * @motto        : Still water run deep
 * @Description  : Modify here please
 * @FilePath     : /ant-js-admin/src/store/modules/app.js
 */

import {
  TOGGLE_MOBILE_TYPE,
  // i18n
  APP_LANGUAGE,
} from '@/store/mutation-types';
import { loadLanguageAsync } from '@/locales';

const app = {
  state: {
    mobileType: 'desktop',
  },
  mutations: {
    [TOGGLE_MOBILE_TYPE]: (state, mobileType) => {
      state.mobileType = mobileType;
    },
  },
  actions: {
    setLang({ commit }, lang) {
      return new Promise((resolve, reject) => {
        commit(APP_LANGUAGE, lang);
        loadLanguageAsync(lang)
          .then(() => {
            resolve();
          })
          .catch((e) => {
            reject(e);
          });
      });
    },
    setDevice({ commit }, device) {
      commit(TOGGLE_MOBILE_TYPE, device);
    },
  },
};

export default app;
